<template>
  <div class="contact-container">
    <!-- 顶部横幅 -->
    <div class="banner">
      <div class="banner-content">
        <h1>留言咨询</h1>
        <p>您的建议和留言是我们进步的动力</p>
      </div>
    </div>

    <!-- 主要内容区域 -->
    <div class="content-section">
      <!-- 联系方式卡片 -->
      <section class="contact-cards">
        <div class="card">
          <i class="el-icon-phone"></i>
          <h3>电话咨询</h3>
          <p>工作日 9:00-18:00</p>
          <p class="highlight">187-0320-7926</p>
        </div>
        <div class="card">
          <i class="el-icon-message"></i>
          <h3>电子邮件</h3>
          <p>7*24小时接收邮件</p>
          <p class="highlight">1179046254@qq.com</p>
        </div>
        <div class="card">
          <i class="el-icon-location"></i>
          <h3>访问地址</h3>
          <p>欢迎实地参观交流</p>
          <p class="highlight">吉林市昌邑区经济技术开发区翰林路77号吉林农业科技学院九站校区</p>
        </div>
      </section>

      <!-- 留言表单 -->
      <section class="message-form">
        <h2>留言咨询</h2>
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
          <el-form-item label="姓名" prop="name">
            <el-input v-model="form.name" placeholder="请输入您的姓名"></el-input>
          </el-form-item>
          <el-form-item label="邮箱" prop="email">
            <el-input v-model="form.email" placeholder="请输入您的邮箱"></el-input>
          </el-form-item>
          <el-form-item label="电话" prop="phone">
            <el-input v-model="form.phone" placeholder="请输入您的联系电话"></el-input>
          </el-form-item>
          <el-form-item label="主题" prop="subject">
            <el-select v-model="form.subject" placeholder="请选择咨询主题" style="width: 100%">
              <el-option label="京剧课程咨询" value="京剧课程咨询"></el-option>
              <el-option label="演出信息查询" value="演出信息查询"></el-option>
              <el-option label="票务预订咨询" value="票务预订咨询"></el-option>
              <el-option label="剧目内容咨询" value="剧目内容咨询"></el-option>
              <el-option label="京剧艺术交流" value="京剧艺术交流"></el-option>
              <el-option label="培训合作洽谈" value="培训合作洽谈"></el-option>
              <el-option label="商务合作机会" value="商务合作机会"></el-option>
              <el-option label="建议与反馈" value="建议与反馈"></el-option>
              <el-option label="其他问题" value="其他问题"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="留言内容" prop="message">
            <el-input
              type="textarea"
              v-model="form.message"
              :rows="4"
              placeholder="请详细描述您的问题或建议"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submitForm" :loading="loading">提交留言</el-button>
            <el-button @click="resetForm('form')">重置</el-button>
          </el-form-item>
        </el-form>
      </section>

      <!-- 地图区域 -->
      <section class="map-section">
        <h2>位置导航</h2>
        <div class="map-container">
          <div id="container" class="amap-box"></div>
        </div>
        <div class="map-info">
          <p><i class="el-icon-location"></i> 吉林市昌邑区经济技术开发区翰林路77号吉林农业科技学院九站校区</p>
          <p><i class="el-icon-phone"></i> 187-0320-7926</p>
        </div>
      </section>
    </div>
  </div>
</template>


<script>
import service from '@/utils/request'


export default {
  name: 'ContactVue',
  data() {
    return {
      loading: false,
      form: {
        name: '',
        email: '',
        phone: '',
        subject: '',
        message: ''
      },
      rules: {
        name: [
          { required: true, message: '请输入姓名', trigger: 'blur' },
          { min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' }
        ],
        email: [
          { required: true, message: '请输入邮箱地址', trigger: 'blur' },
          { type: 'email', message: '请输入正确的邮箱地址', trigger: 'blur' }
        ],
        phone: [
          { required: true, message: '请输入联系电话', trigger: 'blur' },
          { pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号码', trigger: 'blur' }
        ],
        subject: [
          { required: true, message: '请选择咨询主题', trigger: 'change' }
        ],
        message: [
          { required: true, message: '请输入留言内容', trigger: 'blur' },
          { min: 10, max: 500, message: '长度在 10 到 500 个字符', trigger: 'blur' }
        ]
      },
      map: null,
      marker: null
    }
  },
  mounted() {
    document.title = '京剧苑 - 联系我们'
    this.initMap()
    window.scrollTo(0, 0);
  },
  methods: {
    initMap() {
      /* global AMap */
      // 吉林农业科技学院九站校区的经纬度坐标（更新为准确位置）
      const schoolPosition = [126.478819, 43.955836]; 
      
      this.map = new AMap.Map('container', {
        zoom: 16,
        center: schoolPosition,
        resizeEnable: true,
        mapStyle: 'amap://styles/normal'
      })
      
      // 创建信息窗体
      const info = new AMap.InfoWindow({
        content: `
          <div class="info-window">
            <h4>吉林农业科技学院九站校区</h4>
            <p>地址：吉林市昌邑区经济技术开发区翰林路77号</p>
            <p>电话：187-0320-7926</p>
          </div>
        `,
        offset: new AMap.Pixel(0, -30),
        closeWhenClickMap: true
      })

      // 添加标记
      this.marker = new AMap.Marker({
        position: schoolPosition,
        title: '吉林农业科技学院九站校区',
        animation: 'AMAP_ANIMATION_BOUNCE'
      })
      
      // 绑定事件
      this.marker.on('click', () => {
        info.open(this.map, this.marker.getPosition())
      })
      
      this.map.add(this.marker)
      
      // 添加控件，只保留基本控件，移除导航相关功能
      AMap.plugin(['AMap.ToolBar', 'AMap.Scale'], () => {
        // 添加工具栏控件
        const toolbar = new AMap.ToolBar({
          position: 'RB',
          offset: new AMap.Pixel(10, 20)
        })
        
        // 添加比例尺控件
        const scale = new AMap.Scale({
          position: 'LB'
        })
        
        this.map.addControl(toolbar)
        this.map.addControl(scale)
      })

      // 自动打开信息窗体
      setTimeout(() => {
        info.open(this.map, this.marker.getPosition())
      }, 1000)
    },
    
    // 提交留言
    submitForm(){
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.loading = true;
          // 转换为后端需要的字段格式
          const submitData = {
            gbName: this.form.name,
            gbEmail: this.form.email,
            gbPhone: this.form.phone,
            gbTheme: this.form.subject,
            gbContent: this.form.message
          };
          
          service.post('/api/system/guestbook/add', submitData)
          .then(res => {
            this.loading = false;
            if (res.code === 200) {
              this.$message.success('留言提交成功！我们会尽快与您联系。')
              this.resetForm('form')
            } else {
              this.$message.error(res.message || '提交失败，请稍后重试')
            }
          })
          .catch(err => {
            this.loading = false;
            this.$message.error('提交失败：' + (err.message || '网络错误'))
            console.error('提交留言失败:', err)
          })
        }
      })
    },
    
    // 重置表单
    resetForm(formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style scoped>
.contact-container {
  min-height: 100vh;
  padding-bottom: 50px;
  background-color: #f9f5f0;
}

.banner {
  height: 500px;
  background-image: url('@/assets/about/opera_contact.jpg');
  background-size: cover;
  background-position: center;
  position: relative;
  margin-bottom: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.banner:before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(to bottom, rgba(139, 0, 0, 0.7), rgba(0, 0, 0, 0.5));
}

.banner-content {
  position: relative;
  z-index: 1;
  text-align: center;
  color: white;
}

.banner-content h1 {
  font-size: 4rem;
  font-family: 'STXingkai', 'STZhongsong', serif;
  margin-bottom: 15px;
  text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.6);
  color: #FFD700;
  letter-spacing: 10px;
}

.banner-content p {
  font-size: 1.4rem;
  max-width: 600px;
  margin: 0 auto;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
  letter-spacing: 3px;
}

.content-section {
  padding: 30px 8%;
  max-width: 1200px;
  margin: 0 auto;
}

section {
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
  padding: 30px;
  margin-bottom: 30px;
}

.contact-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 30px;
}

.card {
  text-align: center;
  padding: 30px 20px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  transition: all 0.3s ease;
  background-color: #fff;
}

.card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 20px rgba(139, 0, 0, 0.15);
}

.card i {
  font-size: 3rem;
  color: #8B0000;
  margin-bottom: 15px;
  display: block;
}

.card h3 {
  font-size: 1.3rem;
  margin-bottom: 10px;
  color: #333;
  font-family: 'STZhongsong', sans-serif;
}

.card p {
  color: #666;
  margin: 5px 0;
}

.card .highlight {
  font-weight: bold;
  color: #8B0000;
  margin-top: 10px;
  font-size: 1.1rem;
}

.message-form {
  max-width: 800px;
  margin: 0 auto;
  margin-bottom: 30px;
}

.message-form h2 {
  text-align: center;
  font-size: 2rem;
  color: #8B0000;
  margin-bottom: 30px;
  font-family: 'STZhongsong', serif;
}

.map-section h2 {
  text-align: center;
  font-size: 2rem;
  color: #8B0000;
  margin-bottom: 30px;
  font-family: 'STZhongsong', serif;
}

.map-container {
  width: 100%;
  height: 450px;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  margin-bottom: 20px;
}

.amap-box {
  width: 100%;
  height: 100%;
}

.map-info {
  text-align: center;
  margin-top: 15px;
}

.map-info p {
  display: inline-block;
  margin: 0 20px;
  color: #666;
}

.map-info i {
  color: #8B0000;
  margin-right: 5px;
}

@media (max-width: 768px) {
  .banner {
    height: 240px;
  }
  
  .banner-content h1 {
    font-size: 3rem;
    letter-spacing: 5px;
  }
  
  .banner-content p {
    font-size: 1.2rem;
    letter-spacing: 1px;
  }
  
  .content-section {
    padding: 20px 3%;
  }
  
  section {
    padding: 20px;
  }
  
  .map-container {
    height: 350px;
  }
  
  .map-info p {
    display: block;
    margin: 10px 0;
  }
}

@media (max-width: 480px) {
  .banner-content h1 {
    font-size: 2.5rem;
    letter-spacing: 3px;
  }
  
  .map-container {
    height: 300px;
  }
}

.info-window {
  padding: 10px;
  font-family: 'Microsoft YaHei', sans-serif;
}

.info-window h4 {
  margin: 0 0 10px;
  color: #8B0000;
}

.info-window p {
  margin: 5px 0;
  font-size: 0.9rem;
}
</style> 